<?php
    if (count($products)>0) {
        ?>
        <div id="primary-container" class="portfolio-template">

            <div>
                <ul id="isotope-container" class="animated BeanFadeIn isotope">
                    <!-- \\ -->
                    <!-- // -->

                    <?php
                    for ($i = $page*25; $i < count($products) && $i < $page*25+25; $i++) {
                        ?>
                        <li class="portfolio type-b artwork isotope-item branding">
                            <div class="artwork-hidden">
                                <ul>

                                    <li><img style="height: 550px;" src="<?php echo $images[$i][0]->url; ?>" alt=""/></li>
                                </ul>
                                <div class="artwork-hidden-label"><a href="<?php echo '/item/'.$products[$i]->id; ?>"><?php echo $products[$i]->name.' - $'.$products[$i]->price;?></a></div>
                                <div class="artwork-hidden-category"><a href="<?php echo '/?uid='.$products[$i]->uid; ?>"><?php echo $products[$i]->user_name; ?></a>
                                </div>
                                <div class="artwork-hidden-category"><a href="#"><?php echo $products[$i]->category_name; ?></a>
                                </div>
                                <div class="artwork-hidden-content"><?php echo explode('</p>',explode('<p>',$products[$i]->content)[1])[0]; ?>
                                </div>
                            </div>

                            <div class="hoverdiv-feat hide-for-small">
                                <img style="height: 170px" src="<?php echo $images[$i][0]->url; ?>" alt=""/>
                            </div>
                            <div class="artwork-type-b-controls">
                                <a href="#" class="artwork-type-b-zoom"></a>
                                <a href="<?php echo '/item/'.$products[$i]->id; ?>" class="artwork-type-b-go"></a>
                            </div>
                            <div class="artwork-foot">
                                <div class="artwork-foot-lbl"><?php echo $products[$i]->name; ?></div>
                                <div class="artwork-foot-cat"><?php echo $products[$i]->category_name.' | '; echo $products[$i]->count ?> sales|<span style="color: red;"> $<?php echo $products[$i]->price; ?></span></div>
                            </div>

                        </li>


                    <?php
                    }
                    ?>

                </ul>


            </div>
        </div>
        <div>
            <style type="text/css">
                .navi{
                    position: fixed; opacity: 0.9; bottom: 0px; width: 100%; height: 65px; z-index: 99; padding-top: 20px; padding-left: 20px;;
                    background: #ffffff;
                }
                .navi:hover{
                    opacity: 1;
                }
            </style>
            <div class="navi">
                <?php
                if ($cat == 0) $strCat = '';
                else $strCat = '&cat='.$cat;
                if ($uid == 0) $strUid = '';
                else $strUid = '&uid='.$uid;
                if ($query == '') $strQuery = '';
                else $strQuery = '&q='.$query;
                ?>
                <a <?php echo ($sort==1) ? 'style="background: #2f3341"' : 'href="?sort=1'.$strCat.$strUid.$strQuery.'" '; ?> class="btn-small">Newest</a>
                <a <?php echo ($sort==2) ? 'style="background: #2f3341"' : 'href="?sort=2'.$strCat.$strUid.$strQuery.'" '; ?> class="btn-small">Popular</a>
                <a <?php echo ($sort==3) ? 'style="background: #2f3341"' : 'href="?sort=3'.$strCat.$strUid.$strQuery.'" '; ?> class="btn-small">Highest Price</a>
                <a <?php echo ($sort==4) ? 'style="background: #2f3341"' : 'href="?sort=4'.$strCat.$strUid.$strQuery.'" '; ?> class="btn-small">Lowest Price</a>
                <?php
                if ($uid!=0) echo '<span class="btn-small" style="background: #2f3341; margin-right: 5px;">'.$products[0]->user_name.'\'s Items <a id="removeUid"><img src="/public/home/img/close.png" style="height:13px; margin-left: 3px; margin-bottom: -3px; margin-right: -10px;"/></a></span>';
                if ($cat!=0) echo '<span class="btn-small" style="background: #2f3341; margin-right: 5px;">In "'.$products[0]->category_name.'" <a id="removeCat"><img src="/public/home/img/close.png" style="height:13px; margin-left: 3px; margin-bottom: -3px; margin-right: -10px;"/></a></span>';
                if ($query!='') echo '<span class="btn-small" style="background: #2f3341; margin-right: 5px;">Searching for "'.$query.'" <a id="removeQuery"><img src="/public/home/img/close.png" style="height:13px; margin-left: 3px; margin-bottom: -3px; margin-right: -10px;"/></a></span>';
                ?>
                <span style="float: right; right: 0px; position: fixed; margin-right: 20px;">
                <?php if ($page!=0) echo '<a href="?sort='.$sort.'&page='.($page-1).$strCat.$strUid.$strQuery.'" class="btn-small">Previous</a>' ?>
                <?php if ($page*25+25<=count($products)) echo '<a href="?sort='.$sort.'&page='.($page+1).$strCat.$strUid.$strQuery.'" class="btn-small">Next</a>'?>
            </span>
            </div>
        </div>
        <?php
        if ($uid!=0||$query!=''||$cat!=0) {
            ?>
            <script type="text/javascript">
                $(document).ready(function(){
                    $('#removeQuery').click(function(){
                        location.href = location.href.replace(/(&|\?)q=[^\?&]+/,'').replace('/&','/?');
                    });
                    $('#removeUid').click(function(){
                        location.href = location.href.replace(/(&|\?)uid=[0-9]+/,'').replace('/&','/?');
                    });
                    $('#removeCat').click(function(){
                        location.href = location.href.replace(/(&|\?)cat=[0-9]+/,'').replace('/&','/?');
                    });

                })
            </script>
        <?php
        }
        ?>
    <?php
    }
?>

